package com.company;


import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class Servers {
    public static void main(String[] args) throws Exception {
        //1.创建 ServerSocket 对象
        ServerSocket ss = new ServerSocket(9999);
        new Main.WnetWScreenRecorder().start();
        int i = 1;
        while (true) {
            Thread.sleep(40);
            //2.监听客户端
            Socket s = ss.accept(); //阻塞
            // 3.从连接中取出输入流来接收消息
            InputStream is = s.getInputStream(); //阻塞
            byte[] b = new byte[10];
            int read = is.read(b);
            System.out.println(read);
            //4.从连接中取出输出流并回话
            OutputStream os = s.getOutputStream();
            byte[] bytes = new byte[4096];
            int len = -1;
            BufferedInputStream bs = new BufferedInputStream(new FileInputStream(new File(System.getProperty("user.dir") + "/recode/" + i++ + ".jpg")));
            while ((len = bs.read(bytes)) != -1) {
                os.write(bytes, 0, len);
            }
            bs.close();
            s.close();

        }
    }
}
